package com.ry.atomic;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

public class AtomicIntegerFieldUpdaterExp {
    public static void main(String[] args) {
        AtomicIntegerFieldUpdater<Person> atomUpdater =
                AtomicIntegerFieldUpdater.newUpdater(Person.class,"id");
        Person person = new Person(12345);
        atomUpdater.compareAndSet(person,12345,1000);
        System.out.println(person.getId());
    }
}

class  Person {
    volatile int id;

    public Person(int id){
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
